package cn.bbs.ba.socket;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.ServerSocket;
import java.net.Socket;

import cn.bbs.ba.log.LogTrac;

public class BAServer843ForFlex {
	/** 启动端口号 */
	private int port = 843;
	
	public BAServer843ForFlex() {
		init();
	}
	private void init(){
		
		try {
			String xml = "<?xml version=\"1.0\"?><cross-domain-policy><site-control permitted-cross-domain-policies=\"all\"/><allow-access-from domain=\"*\" to-ports=\"*\"/></cross-domain-policy>\0";

			ServerSocket serverSocket = new ServerSocket(port);
			
			while(true){
				Socket socket = serverSocket.accept();
				BufferedReader br = new BufferedReader(new InputStreamReader(socket.getInputStream(), "UTF-8"));
				PrintWriter pw = new PrintWriter(socket.getOutputStream());
				char[] by = new char[22];
				br.read(by, 0, 22);
				String s = new String(by);
				System.out.println("s="+s);
				if (s.equals("<policy-file-request/>")) 
				{
					 pw.print(xml);
					 pw.flush();
					 br.close();
					 pw.close();
					 socket.close();
				}
			}

		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	/**
	 * 启动843
	 * @param args
	 */
	public static void main(String[] args) {
		LogTrac.info("843端口开始启动.....");
		new BAServer843ForFlex();
		LogTrac.info("843端口停止结束.....");
	}
}
